module.exports = app => {
  const express = require('express')
  const router = express.Router()
  const multer = require('multer')
  const path = require('path')
  // 身份验证中间件
  const authMiddleware = require('../../middleWare/auth')
  const throwError = require('../../middleWare/throwErr')



  router.post('/', async (req, res) => {
    const file = req.file
    // uploads文件夹经过后端静态文件处理
    file.url = `http://localhost:3000/uploads/${file.filename}`
    res.send(req.file)
  })

  // 上传的文件存储地址
  const upload = multer({ dest: path.join(__dirname, '../../uploads') })

  app.use('/admin/api/upload', authMiddleware(), throwError(), upload.single('uploadfile'), router)
}